package com.qk.service.impl;

import com.qk.mapper.BusinessMapper;
import com.qk.mapper.ClueMapper;
import com.qk.service.ReportService;
import com.qk.vo.OverviewVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ClueMapper clueMapper;
    @Autowired
    private BusinessMapper businessMapper;
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    //@Transactional(rollbackFor = Exception.class)
    @Override
    public OverviewVo getOverview() {
        log.info("redis获取报表");
        Object object = redisTemplate.opsForValue().get("DATA_VIEW");
        if (object != null){
            log.info("redis获取报表成功");
            return (OverviewVo) object;
        }


        OverviewVo clueOverview =clueMapper.getClueOverview();
        OverviewVo businessOverview =businessMapper.getBusinessOverview();

        BeanUtils.copyProperties(clueOverview,businessOverview,
                "businessTotal","businessWaitAllot","businessWaitFollow",
                "businessFollowing","businessFalse","businessConvertCustomer");

        redisTemplate.opsForValue().set("DATA_VIEW",businessOverview,1, TimeUnit.MINUTES);
        return businessOverview;
    }
}
